/**Register presenter**/
// $codepro.audit.disable expressionValue, numericLiterals, com.instantiations.assist.eclipse.analysis.unusedReturnValue
package edu.gatech.presenters;

import javax.swing.JOptionPane;

import edu.gatech.userclasses.SysAdmin;
import edu.gatech.userclasses.User;
import edu.gatech.userclasses.UserType;
import edu.gatech.utilities.Persistence;

/** Registers a user into  the system
 * 
 * @author Tyler Natoli
 * @version 1.0
 */
public class RegisterPresenter {

	/**The system admin that is registering a patient**/
	private final SysAdmin currentAdmin;
	
	/** Presenter that sets the current admin
	 * 
	 * @param currentAdmin
	 */
	public RegisterPresenter(SysAdmin currentAdmin){
		this.currentAdmin = currentAdmin;
	}
	
	/** Registers a user based on which radio button
	 * was selected
	 * @param username
	 * @param password
	 * @param radioButton
	 */
	public void register(String username, String password, int radioButton){
		boolean available = true;
		for (User u : Persistence.getUserList()){
			if(u.getUsername().equals(username)){
				available = false;
			}
		}
		if(available){
			if(radioButton == 0){
				currentAdmin.addUser(username, password, UserType.PATIENT);
				JOptionPane.showMessageDialog(null, 
						"Thank you for registering with our system. Your account has" +
				"been creeated!");
			}
			else if(radioButton == 1){
				currentAdmin.addUser(username, password, UserType.NURSE);
				JOptionPane.showMessageDialog(null, 
						"Thank you for registering with our system. Your account has" +
				"been creeated!");
			}
			else if(radioButton == 2){
				currentAdmin.addUser(username, password, UserType.DOCTOR);
				JOptionPane.showMessageDialog(null,
						"Thank you for registering with our system. Your account has" +
				"been creeated!");
			}
			else if(radioButton == 3){
				currentAdmin.addUser(username, password, UserType.SYSADMIN);
				JOptionPane.showMessageDialog(null, 
						"Thank you for registering with our system. Your account has" +
				"been creeated!");
			}
			else{
				JOptionPane.showMessageDialog(null, "Please select your user type");
			}
		}
		else{
			JOptionPane.showMessageDialog(null, 
					"This username is already registered in our system");
		}
	}
	
	/** Overrides toString
	 * @return String
	 */
	public String toString(){
		return "Register panel";
	}
}
